home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / icon / packages.lha / packages / atari / ats.arc / TESTS.ARC / SIEVE.ICN < prev    next >
Text File  |  1990-03-28  |  563b  |  21 lines

  1. #
  2. #          S I E V E   O F   E R A T O S T H E N E S
  3. #
  4.  
  5. #  This program illustrates the use of sets in implementing the
  6. #  classical sieve algorithm for computing prime numbers.
  7.  
  8. procedure main()
  9.    local limit, s, i
  10.    limit := 100
  11.    s := set()
  12.    every insert(s,1 to limit)
  13.    every member(s,i := 2 to limit) do
  14.       every delete(s,i + i to limit by i)
  15.    delete(s,1)
  16.    primes := sort(s)
  17.    write("There are ",*primes," primes in the first ",limit," integers.")
  18.    write("The primes are:")
  19.    every write(right(!primes,*limit + 1))
  20. end
  21.